package com.oop.example.work.esport;

import com.oop.example.processing.UnloadProcessor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author -
 */
public class Esp2PortUnloadProcessor implements UnloadProcessor {

    @Override
    public StringBuffer process(StringBuffer src) {
        return me(ms(src));
    }

    StringBuffer ms(StringBuffer src) {
        StringBuffer sb = new StringBuffer(src.length());
        try {
            Pattern patt = Pattern.compile("<markStart></markStart>");
            Matcher m = patt.matcher(src);

            while (m.find()) {
                String text = m.group(1);
                text = "<markStart/>";
                m.appendReplacement(sb, Matcher.quoteReplacement(text));
            }
            m.appendTail(sb);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            sb = src;
        }
        return sb;
    }

    StringBuffer me(StringBuffer src) {
        StringBuffer sb = new StringBuffer(src.length());
        try {
            Pattern patt = Pattern.compile("<markEnd></markEnd>");
            Matcher m = patt.matcher(src);

            while (m.find()) {
                String text = m.group(1);
                text = "<markEnd/>";
                m.appendReplacement(sb, Matcher.quoteReplacement(text));
            }
            m.appendTail(sb);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            sb = src;
        }
        return sb;
    }
}
